﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using ReaWTM.LayuiHelper.Common;
using System.Reflection;
using WalkingTec.Mvvm.Core.Implement;
using WalkingTec.Mvvm.Core;

namespace ReaWTM
{
	public static class MvcExtensions
	{
		public static IApplicationBuilder UseReaStaticFiles(this IApplicationBuilder app)
		{
			app.UseStaticFiles(new StaticFileOptions
			{
				RequestPath = new PathString("/_js"),
				FileProvider = new EmbeddedFileProvider(Assembly.GetExecutingAssembly())
			});
			return app;
		}

		public static IServiceCollection AddReaWtmLayui(this IServiceCollection services)
		{
			services.Remove(new ServiceDescriptor(typeof(IUIService), typeof(DefaultUIService), ServiceLifetime.Singleton));
			services.AddSingleton<IUIService, LayuiUIService>();

			return services;
		}
	}
}
